{{define "main/netdisk"}}

{{template "base" .}}
<head>
    <meta charset="UTF-8">
    <title>{{.thisDir.FileName}}</title>
</head>
<body>
<h3>{{.warning}}</h3>
<form method="post" action="/add" enctype="multipart/form-data">
    <input type="file" name="file" required multiple>
    <input type="hidden" name="parent_dir" value="{{.thisDir.Id}}">
    <input type="hidden" name="next" value="/netdisk/{{.thisDir.Id}}">
    <button>上传文件</button>
</form>
<hr>
<form method="post" action="/add" enctype="multipart/form-data">
    <input type="file" name="file" required webkitdirectory>
    <input type="hidden" name="parent_dir" value="{{.thisDir.Id}}">
    <input type="hidden" name="next" value="/netdisk/{{.thisDir.Id}}">
    <button>上传文件夹</button>
</form>
<hr>
<form method="get" action="/create_dir/">
    <input type="hidden" name="parent_dir" value="{{.thisDir.Id}}">
    <input type="hidden" name="next" value="/netdisk/{{.thisDir.Id}}">
    <label for="name">名称</label>
    <input type="text" name="name" id="name" required>
    <button>新建文件夹</button>
</form>
<hr>
{{if ne .thisDir.ParentDir 0}}
<a href="/parent_dir/{{.thisDir.Id}}">返回</a>
<br>
<hr>
{{end}}
<script>
    function delete_file(file_id, file_name) {
        if (confirm('是否删除文件' + file_name + '?')) {
            location.href = "/delete_file/" + file_id;
        }
    }
</script>
{{range .sonFiles}}
<a href="/netdisk/{{.Id}}" {{if eq .Type 0}} download="{{.FileName}}" {{end}}>
    {{if eq .Type 0}}
    <img src="/static_file/file.png" height="20px" width="15px" style="position:relative;top:3px">
    {{else}}
    <img src="/static_file/dir.png" height="20px" width="25px" style="position:relative;top:3px">
    {{end}}
    {{.FileName}}
</a>
<button onclick="delete_file('{{.Id}}','{{.FileName}}')" style="position:absolute;right:40px;">删除</button>
<hr>
{{end}}
</body>
{{end}}